<?php
/**
 * Created by PhpStorm.
 * User: jsq
 * Date: 2017/5/3 0003
 * Time: 14:05
 */
namespace app\admin\controller;
use app\common\model\Order;
use app\common\model\Order_log;
use think\Db;
use app\common\traits\Excel as Excelapi;
use think\Request;


class Excel extends Admin
{
    use Excelapi;

//    public function exceldr(Request $request){
//
//        $file = request()->file('excel');
//
//        if($file){
//
//            $info = $file->move('public/'. 'uploads/');
//
//            $file_name = 'public/uploads/'.$info->getSaveName();
//
////            $arr  =  $this->impUser($file_name);
//            for ($i=0;$i<=3;$i++){
//                $data = read($file_name,$i);
//                $data=collect($data)->flatten(1)->all();
//                foreach ($data as $val){
//                    $io['maphone'] = $val;
//                    $io['type'] = $i+1;
//                    $res = Db::name('erbohui')->insert($io);
//                    unset($data);
//                }
//            }
//            if($res){
//                echo '成功';
//            }
////            halt($data[4]);
//
//            unlink($file_name);
//        }
//
//
////        $this->assign('info',$arr);
//        return $this->fetch();
//    }

    public function exceldr(Request $request){

        $file = request()->file('excel');

        if($file){
            $info = $file->move('public/'. 'uploads/');
            $file_name = 'public/uploads/'.$info->getSaveName();
            $arr  =  $this->impUser($file_name);
            unlink($file_name);
        }

        $this->assign('info',$arr);
        return $this->fetch();
    }

    public function exceldc(){
        $map = $this->request->param();
        $order = new Order;
        $data = $order->maps($map);

        $maps = $order->where($data)->cache(600)->select();
        $title = ['ID','姓名','电话','家人电话','预产期','地区','收集医院','医院渠道','业务状态'];
        foreach ($maps as $k => $v){
            $arr[$k][] = $v['id'];
            $arr[$k][] = $v['name'];
            $arr[$k][] = $v['maphone'];
            $arr[$k][] = $v['otherphone'];
            $arr[$k][] = $v['yctime'];
            $arr[$k][] = $v['area_text'];
            $arr[$k][] = $v['yyxx_text'];
            $arr[$k][] = $v['menzhen_text'];
            $arr[$k][] = $v['state_text'];
        }

        $this->exportexcel($arr,$title);

    }


}